/**@Title   GradedDao.java
 * @Package com.gong.dao
 * @Desc    
 * @Author  GongWenhua
 * @Date    2017年7月17日 下午5:15:56
 * @Version 1.0
*/
package com.gong.dao;

import java.sql.ResultSet;
import java.sql.SQLException;

import javax.annotation.Resource;
import javax.swing.tree.TreePath;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import com.gong.bean.Grade;

@Repository
public class GradedDao {
	
	@Resource
	private JdbcTemplate jdbcTemplate;
	
	public Grade selectByGradeNum(String gradeNum){
		String sql = "select * from grade where grade_num = ?";
		RowMapper<Grade> rowMapper = new GradeRowMapper();
		return jdbcTemplate.queryForObject(sql, new Object[]{gradeNum},rowMapper);
		
	}
	
}
class GradeRowMapper implements RowMapper<Grade>{
	@Override
	public Grade mapRow(ResultSet rs, int rowNum) throws SQLException {
		// TODO Auto-generated method stub
		Grade grade = new Grade();
		grade.setGradeNum(rs.getString("grade_num"));
		grade.setId(rs.getInt("id"));
		grade.setTeacherId(rs.getInt("teacher_id"));
		return grade;
	}
	
}
